package com.youku.adSDK.view
{
   import flash.display.Sprite;
   import com.youku.adSDK.ADEventDispather;
   import com.youku.adSDK.view.components.VideoAD;
   import com.youku.adSDK.model.vo.GroupData;
   import flash.utils.Timer;
   import com.youku.adSDK.ADContext;
   import flash.text.TextField;
   import com.youku.adSDK.view.events.ADEvent;
   import com.youku.adSDK.Utils.AdFsoTools;
   import com.youku.adSDK.YoukuAdEvent;
   import com.youku.adSDK.ADConstant;
   import flash.events.TimerEvent;
   import flash.utils.getTimer;
   import com.youku.adSDK.model.vo.ADData;
   import com.youku.adSDK.YoukuAdManager;
   import com.youku.adSDK.Utils.AdOpenWindow;
   import flash.net.URLRequest;
   import flash.utils.setTimeout;
   import flash.external.ExternalInterface;
   import flash.utils.clearTimeout;
   import com.youku.adSDK.view.events.VideoADEvent;
   import flash.net.sendToURL;
   import flash.net.SharedObject;
   
   public class FrontMediator extends Object
   {
      
      public function FrontMediator(param1:ADEventDispather, param2:ADContext) {
         super();
         this._mainMc = param2.mainMc;
         this._eventDispather = param1;
         this._context = param2;
         this._debugTF = new TextField();
         this._debugTF.width = 300;
         this._debugTF.height = 200;
         this._debugTF.background = true;
         this._debugTF.backgroundColor = 16777215;
         this._debugTF.border = true;
         YoukuAdManager.debugTF = this._debugTF;
      }
      
      private var _mainMc:Sprite;
      
      private var _eventDispather:ADEventDispather;
      
      private var _front:VideoAD;
      
      private var _support:VideoAD;
      
      private var _soinfo:Object;
      
      private var _groupData:GroupData;
      
      private var _seedTimePoint:Number;
      
      private var _seedPointType:String;
      
      private var _PIPDataArr:Array;
      
      private var _totalTime:Number = 0;
      
      private var _frontStartTime:Number = 0;
      
      private var _checkTimer:Timer;
      
      private var _checkStartTimerTime:Number = 0;
      
      private var _checkStartDateTime:Number = 0;
      
      private var _checkCount:int = 0;
      
      private var _isCheckDiff:Boolean = false;
      
      private var _lastAdTime:Number = 0;
      
      private var _jsTimeID:Number;
      
      private var _jsTimeOutID:Number;
      
      private var _jsADTime:Number = 3;
      
      private var _width:Number = 0;
      
      private var _height:Number = 0;
      
      private var _barH:Number;
      
      private var _shutData:Boolean = false;
      
      private var _action:int = 0;
      
      private var _volume:Number = -1;
      
      private var _jsADTimeout:Boolean = false;
      
      private var _jsADEnd:Boolean = false;
      
      private var _FSOavailable:Boolean = true;
      
      private var _ltadview:Number = 0;
      
      private var _stadview:Number = 0;
      
      private var _adplaystarted:Boolean = false;
      
      private var _stcrzay:Number = 0;
      
      private var _adholderCallback:Function;
      
      private const AD_CHECK_TIMEOUT:Number = 1.08E7;
      
      private const DIFF_CHECK_COUNT:int = 3;
      
      private const DIFF_CHECK_INTERVAL:Number = 200;
      
      private const DIFF_CHECK_NSTIME_DIFFNUM:Number = 400;
      
      private const ADPLAY_DIFF_TIME:Number = 5;
      
      private var _context:ADContext;
      
      private var _debugTF:TextField;
      
      private var _isPreloadComplete:Boolean = false;
      
      private var _adPlayTimer:Timer;
      
      private var _sendLoadCompleteTime:int = 8;
      
      private var _isShowHolder:Boolean = false;
      
      private var _st:int = 0;
      
      private var _bt:int = 0;
      
      public function init() : void {
         this._eventDispather.addEventListener(ADEvent.REQUEST_AND_PLAY_FRONT_AD,this.onPlayerRequestPlayAD);
         this._eventDispather.addEventListener(ADEvent.CHANGE_SIZE,this.onPlayerResize);
         this._eventDispather.addEventListener(ADEvent.CHANGE_VOLUME,this.onPlayerChangeVolume);
         this._eventDispather.addEventListener(ADEvent.COMMON_ERROR,this.onPlayerError);
         this._eventDispather.addEventListener(ADEvent.COMMON_RESET,this.onPlayerReset);
         this._soinfo = AdFsoTools.getADRefreshInfo();
         this.addEvents();
      }
      
      public function reinit() : void {
         this.addEvents();
      }
      
      private function addEvents() : void {
         this._eventDispather.addEventListener(ADEvent.FRONT_DATA_LOADED,this.onADEvent);
         this._eventDispather.addEventListener(ADEvent.FRONT_DATA_IS_NULL,this.onADEvent);
         this._eventDispather.addEventListener(ADEvent.FRONT_DATA_INVALID,this.onADEvent);
         this._eventDispather.addEventListener(ADEvent.FRONT_DATA_LOAD_ERROR,this.onADEvent);
         this._eventDispather.addEventListener(ADEvent.FRONT_DATA_LOAD_TIME_OUT,this.onADEvent);
         this._eventDispather.addEventListener(ADEvent.FRONT_SEED_DATA_LOADED,this.onADEvent);
         this._eventDispather.addEventListener(ADEvent.FRONT_LOAD_TIME,this.onADEvent);
         this._eventDispather.addEventListener(ADEvent.ADHOLDER_COMPLETE,this.onADEvent);
      }
      
      private function removeEvents() : void {
         this._eventDispather.removeEventListener(ADEvent.FRONT_DATA_LOADED,this.onADEvent);
         this._eventDispather.removeEventListener(ADEvent.FRONT_DATA_IS_NULL,this.onADEvent);
         this._eventDispather.removeEventListener(ADEvent.FRONT_DATA_INVALID,this.onADEvent);
         this._eventDispather.removeEventListener(ADEvent.FRONT_DATA_LOAD_ERROR,this.onADEvent);
         this._eventDispather.removeEventListener(ADEvent.FRONT_DATA_LOAD_TIME_OUT,this.onADEvent);
         this._eventDispather.removeEventListener(ADEvent.FRONT_SEED_DATA_LOADED,this.onADEvent);
         this._eventDispather.removeEventListener(ADEvent.FRONT_LOAD_TIME,this.onADEvent);
         this._eventDispather.removeEventListener(ADEvent.ADHOLDER_COMPLETE,this.onADEvent);
      }
      
      private function onADEvent(param1:ADEvent) : void {
         var _loc2_:* = NaN;
         var _loc3_:* = NaN;
         var _loc4_:* = NaN;
         var _loc5_:Object = null;
         this._action--;
         if((this._shutData) || this._action > 0)
         {
            return;
         }
         switch(param1.type)
         {
            case ADEvent.FRONT_DATA_LOADED:
               this._groupData = param1.data as GroupData;
               this.showAD();
               break;
            case ADEvent.FRONT_SEED_DATA_LOADED:
               this._groupData = param1.data as GroupData;
               this.playVideo();
               this.resetFC();
               this.seedHandler();
               break;
            case ADEvent.FRONT_DATA_IS_NULL:
               this.playVideo();
               this.resetFC();
               break;
            case ADEvent.FRONT_DATA_INVALID:
               this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_LOAD_TIME,
                  {
                     "isError":true,
                     "type":ADConstant.TYPE_AD_FRONT_REQUEST,
                     "errorCode":ADConstant.ERROR_CODE_AD_KEY
                  }));
               this._st = 2;
               this._bt = 3;
               this.showADHolder(false);
               break;
            case ADEvent.FRONT_DATA_LOAD_ERROR:
            case ADEvent.FRONT_DATA_LOAD_TIME_OUT:
               if(this._context.vip == true)
               {
                  this.close();
               }
               else
               {
                  this.checkFC();
               }
               break;
            case ADEvent.FRONT_LOAD_TIME:
               _loc2_ = param1.data.lt;
               _loc3_ = param1.data.start;
               _loc4_ = param1.data.end;
               this._context.ltadrequest_start = _loc3_;
               this._context.ltadrequest_end = _loc4_;
               this._context.ltadrequest = _loc2_;
               if(param1.data.error == true)
               {
                  _loc5_ = {};
                  _loc5_.type = "error";
                  _loc5_.stage = ADConstant.LOAD_STAGE_AD_REQUEST;
                  this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_LOAD_TIME_REQUEST,_loc5_));
               }
               break;
            case ADEvent.ADHOLDER_COMPLETE:
               this.onADHolderFinished();
               break;
         }
         this.recordTime();
      }
      
      private function onPlayerError(param1:ADEvent) : void {
         this.close();
      }
      
      private function onPlayerReset(param1:ADEvent) : void {
         this.close();
         this.reinit();
      }
      
      private function close() : void {
         if(this._front)
         {
            if(this._mainMc.contains(this._front))
            {
               this._mainMc.removeChild(this._front);
            }
            this._front.dispose();
         }
         this._front = null;
         if(this._support)
         {
            if(this._mainMc.contains(this._support))
            {
               this._mainMc.removeChild(this._support);
            }
            this._support.dispose();
         }
         this._support = null;
         this._action = 0;
         this._shutData = true;
         this._jsADTimeout = false;
         this._jsADEnd = false;
         this._adplaystarted = false;
         if(this._checkTimer)
         {
            this._checkTimer.removeEventListener(TimerEvent.TIMER,this.onCheckTimer);
            this._checkTimer.stop();
         }
         this.allDone(true);
      }
      
      private function onPlayerRequestPlayAD(param1:ADEvent) : void {
         this._totalTime = 0;
         if(this._context.isTudouPlayer)
         {
            this.allDone(true);
            return;
         }
         if((param1.data) && (param1.data.skip) && param1.data.skip == true)
         {
            this.allDone(true);
            return;
         }
         this._shutData = false;
         this._action++;
         this._checkStartDateTime = new Date().time;
         this._checkStartTimerTime = getTimer();
         this._checkCount = 0;
         this._lastAdTime = 0;
         this._isCheckDiff = false;
         this._checkTimer = new Timer(this.DIFF_CHECK_INTERVAL);
         this._checkTimer.addEventListener(TimerEvent.TIMER,this.onCheckTimer);
         this._checkTimer.start();
         this._adPlayTimer = new Timer(500);
         this._adPlayTimer.addEventListener(TimerEvent.TIMER,this.onAdPlayTimer);
         this._adPlayTimer.start();
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.DO_FRONT));
      }
      
      private function onPlayerResize(param1:ADEvent) : void {
         this._width = param1.data.width;
         this._height = param1.data.height;
         this._barH = param1.data.cheight;
      }
      
      private function onPlayerChangeVolume(param1:ADEvent) : void {
         this._volume = param1.data.volume;
      }
      
      private function showAD() : void {
         var adData:ADData = null;
         YoukuAdManager.frontPlaying = true;
         if((this._groupData.JS) && this._groupData.JS.length > 0)
         {
            adData = this._groupData.JS[0] as ADData;
         }
         if((adData) && !(Number(adData.VT) == 2))
         {
            if(Number(adData.AL) == 0)
            {
               this._jsADTime = int.MAX_VALUE;
            }
            else
            {
               this._jsADTime = (this._jsADTime + Number(adData.AL)) * 1000;
            }
            this.sendData(adData.SUS);
            if(Number(adData.VT) == 1)
            {
               AdOpenWindow.open(new URLRequest(String(adData.VC)),"_self");
            }
            this._jsTimeID = setTimeout(this.jsTimeout,3000);
            this._stcrzay = getTimer();
            this._context.ltcrazy_start = new Date().getTime();
            try
            {
               ExternalInterface.addCallback("jsAdStart",this.jsAdStart);
               ExternalInterface.addCallback("jsAdEnd",this.jsAdEnd);
            }
            catch(e:Error)
            {
               trace("error: " + [e.getStackTrace()]);
            }
            try
            {
               ExternalInterface.call("Nova.addScriptContent",escape(adData.JS));
            }
            catch(e:Error)
            {
               trace("error: " + [e.getStackTrace()]);
            }
         }
         else
         {
            if((adData) && Number(adData.VT) == 2)
            {
               AdOpenWindow.open(new URLRequest(String(adData.VC)),"_self");
            }
            this.initVideoAD();
         }
      }
      
      private function jsAdStart() : Number {
         clearTimeout(this._jsTimeID);
         this._jsTimeOutID = setTimeout(this.jsAdOverTime,this._jsADTime);
         return this._jsADTimeout?0:1;
      }
      
      private function jsAdOverTime() : void {
         clearTimeout(this._jsTimeOutID);
         try
         {
            ExternalInterface.call("adOverTime");
         }
         catch(e:Error)
         {
            trace("error: " + [e.getStackTrace()]);
         }
      }
      
      private function jsAdEnd() : void {
         clearTimeout(this._jsTimeID);
         clearTimeout(this._jsTimeOutID);
         this._jsADEnd = true;
         if(!this._front && !this._support)
         {
            this.initVideoAD();
         }
      }
      
      private function jsTimeout() : void {
         this._jsADTimeout = true;
         this.clearJSAD();
         if(!this._front && !this._support)
         {
            this.initVideoAD();
         }
      }
      
      private function clearJSAD() : void {
         try
         {
            ExternalInterface.call("adOverTime");
         }
         catch(e:Error)
         {
            trace("error: " + [e.getStackTrace()]);
         }
      }
      
      private function initVideoAD() : void {
         var _loc1_:* = 0;
         var _loc2_:ADData = null;
         this._totalTime = 0;
         this._PIPDataArr = [];
         if(this._groupData.VAL)
         {
            _loc1_ = 0;
            while(_loc1_ < this._groupData.VAL.length)
            {
               _loc2_ = this._groupData.VAL[_loc1_] as ADData;
               if(_loc2_.VT != 2)
               {
                  this._totalTime = this._totalTime + _loc2_.AL;
               }
               this._PIPDataArr.push(
                  {
                     "F1":_loc2_.BRS,
                     "CU":_loc2_.CU
                  });
               _loc1_++;
            }
         }
         this._soinfo.totalTime = this._totalTime;
         this._soinfo.dataObj = this.dataObjeded(this._groupData);
         this._soinfo.videoId = this._context.videoId;
         this._soinfo.nowTime = -1;
         this._soinfo.seedTime = new Date().getTime();
         if(!this._totalTime)
         {
            this._soinfo.nowTime = this._totalTime;
         }
         this._stadview = getTimer();
         this._context.ltadview_start = new Date().getTime();
         if(this._stcrzay != 0)
         {
            this._context.ltcrazy_end = new Date().getTime();
            this._context.ltcrazy = this._context.ltcrazy_end - this._context.ltcrazy_start;
            this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_LOAD_TIME,
               {
                  "isError":false,
                  "type":ADConstant.TYPE_CRAZY,
                  "errorCode":null
               }));
         }
         if(this._totalTime == 0)
         {
            this.onFrontPlayError();
         }
         else
         {
            this.initFront();
         }
      }
      
      private function initFront() : void {
         this._front = new VideoAD();
         this._front.ADType = ADConstant.FRONT_AD;
         this._front.setVolume(this._volume);
         this._mainMc.addChild(this._front);
         this._front.addEventListener(VideoADEvent.PLAY_START,this.onFrontPlayStart);
         this._front.addEventListener(VideoADEvent.LOAD_COMPLETE,this.onFrontLoadComplete);
         this._front.addEventListener(VideoADEvent.PLAY_OVER,this.onFrontEnd);
         this._front.addEventListener(VideoADEvent.PLAY_ERROR,this.onFrontEnd);
         this._front.addEventListener(VideoADEvent.PLAY_BLOCKED,this.onFrontEnd);
         this._front.addEventListener(VideoADEvent.AD_VT,this.onFrontVT);
         this._front.addEventListener(VideoADEvent.AD_SKIP,this.onFrontSkip);
         this._front.PIPDataArr = this._PIPDataArr;
         this._front.init(this._groupData.VAL,this._context,this._eventDispather,this._width,this._height,this._barH);
         this._front.showPaidButton();
         if(this._context.vip == true || !(this._context.winType == "interior") || this._groupData.SKIP == 0)
         {
            this._front.hidePaidButton();
         }
         this._front.play();
         this._frontStartTime = new Date().time;
      }
      
      private function onAdPlayTimer(param1:TimerEvent) : void {
         var _loc2_:* = NaN;
         if((this._adplaystarted) && (this._isPreloadComplete) && !(this._totalTime == 0))
         {
            _loc2_ = this._totalTime - this._front.getCurrentTime();
         }
         if(this._isShowHolder)
         {
            _loc2_ = YoukuAdManager.adHoldMediator.getCurrentTime();
         }
         if(!isNaN(_loc2_) && _loc2_ <= this._sendLoadCompleteTime)
         {
            this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_FRONT_LOAD_COMPLETE));
            if(this._adPlayTimer)
            {
               this._adPlayTimer.removeEventListener(TimerEvent.TIMER,this.onAdPlayTimer);
               this._adPlayTimer.stop();
            }
         }
      }
      
      private function onCheckTimer(param1:TimerEvent) : void {
         var _loc2_:Number = getTimer() - this._checkStartTimerTime;
         var _loc3_:Number = new Date().time - this._checkStartDateTime;
         this._checkStartTimerTime = getTimer();
         this._checkStartDateTime = new Date().time;
         if(Math.abs(_loc3_ - _loc2_) >= this.DIFF_CHECK_INTERVAL / 2)
         {
            this._checkCount++;
            if(this._checkCount >= this.DIFF_CHECK_COUNT)
            {
               this._checkTimer.stop();
               this._isCheckDiff = true;
            }
         }
         if(this._isCheckDiff)
         {
            ExternalInterface.call("ljllq");
            this._st = 1;
            this._bt = 2;
            this.showADHolder(true);
            return;
         }
      }
      
      private function onFrontSkip(param1:VideoADEvent) : void {
         this.onFrontPlayOver();
      }
      
      private function onFrontPlayStart(param1:VideoADEvent) : void {
         var e:VideoADEvent = param1;
         if(!this._adplaystarted)
         {
            this._adplaystarted = true;
            this.recordLoadTime();
            this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_LOAD_TIME,
               {
                  "isError":false,
                  "type":ADConstant.TYPE_AD,
                  "errorCode":null
               }));
            this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_FRONT_START_TO_PLAY));
            if(this._groupData.SKIP == 0)
            {
               this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_SKIP_SHOW));
            }
         }
         if(this._soinfo.nowTime == -1)
         {
            this.sendReadyOrError();
            this._soinfo.nowTime = 0;
            this._soinfo.seedTime = new Date().getTime();
            try
            {
               AdFsoTools.saveADRefreshInfo(this._soinfo);
            }
            catch(erro:Error)
            {
               trace(erro.getStackTrace());
            }
         }
      }
      
      private function onSupportPlayStart(param1:VideoADEvent) : void {
         var e:VideoADEvent = param1;
         if(!this._adplaystarted)
         {
            this._adplaystarted = true;
            this.recordLoadTime();
         }
         if(this._soinfo.nowTime == -1 && !this._front)
         {
            this.sendReadyOrError();
            this._soinfo.nowTime = 0;
            this._soinfo.seedTime = new Date().getTime();
            try
            {
               AdFsoTools.saveADRefreshInfo(this._soinfo);
            }
            catch(erro:Error)
            {
               trace(erro.getStackTrace());
            }
         }
      }
      
      private function recordLoadTime() : void {
         var _loc1_:Number = getTimer();
         this._ltadview = _loc1_ - this._stadview;
         this._context.ltadview_end = new Date().getTime();
         this._context.ltadview = this._ltadview;
      }
      
      private function onFrontLoadComplete(param1:VideoADEvent) : void {
         this._isPreloadComplete = true;
      }
      
      private function onFrontEnd(param1:VideoADEvent) : void {
         this.checkFrontPlayTime(param1);
      }
      
      private function onFrontVT(param1:VideoADEvent) : void {
      }
      
      private function onFrontPlayOver() : void {
         this.resetFC();
         YoukuAdManager.frontOverTime = getTimer();
         var _loc1_:Number = 0;
         if(this._front)
         {
            _loc1_ = this._front.totalTime;
            try
            {
               if(this._mainMc.contains(this._front))
               {
                  this._mainMc.removeChild(this._front);
               }
            }
            catch(error:Error)
            {
            }
            this._front.dispose();
         }
         if(this._front)
         {
            if(this._support)
            {
               this._support.visible = true;
               this._support.play();
            }
            else
            {
               this.allDone(true);
            }
            this.seedSo(this._soinfo.nowTime + _loc1_);
            return;
         }
         if(this._support)
         {
            this._support.visible = true;
            this._support.play();
         }
         else
         {
            this.allDone(true);
         }
         this.seedSo(this._soinfo.nowTime + _loc1_);
      }
      
      private function onFrontPlayError() : void {
         this.resetFC();
         if(this._front)
         {
            if(this._mainMc.contains(this._front))
            {
               this._mainMc.removeChild(this._front);
            }
            this._front.dispose();
         }
         this.sendReadyOrError();
         this.allDone(true);
      }
      
      private function onFrontPlayBlocked() : void {
         if(this._front)
         {
            try
            {
               if(this._mainMc.contains(this._front))
               {
                  this._mainMc.removeChild(this._front);
               }
            }
            catch(error:Error)
            {
            }
            this._front.dispose();
         }
         if(this._front)
         {
            this.checkFC();
            return;
         }
         this.checkFC();
      }
      
      private function checkFrontPlayTime(param1:VideoADEvent) : void {
         this._adholderCallback = null;
         switch(param1.type)
         {
            case VideoADEvent.PLAY_OVER:
               this._adholderCallback = this.onFrontPlayOver;
               break;
            case VideoADEvent.PLAY_ERROR:
               this._adholderCallback = this.onFrontPlayError;
               break;
            case VideoADEvent.PLAY_BLOCKED:
               this._adholderCallback = this.onFrontPlayBlocked;
               break;
         }
         var _loc2_:Number = new Date().time;
         var _loc3_:Number = int((_loc2_ - this._frontStartTime) / 1000);
         var _loc4_:Number = this._totalTime - _loc3_;
         trace("why check:",_loc2_,this._frontStartTime,_loc3_,this._totalTime - _loc3_,_loc4_);
         if(_loc4_ > this.ADPLAY_DIFF_TIME)
         {
            this.sendReadyOrError();
            this._st = 2;
            this._bt = 6;
            this.showADHolderHelper(ADConstant.AD_TIME_LESS,_loc4_);
         }
         else
         {
            this._adholderCallback.call();
         }
      }
      
      private function allDone(param1:Boolean) : void {
         YoukuAdManager.frontPlaying = false;
         this.removeEvents();
         if(this._checkTimer)
         {
            this._checkTimer.removeEventListener(TimerEvent.TIMER,this.onCheckTimer);
            this._checkTimer.stop();
         }
         if(this._adPlayTimer)
         {
            this._adPlayTimer.removeEventListener(TimerEvent.TIMER,this.onAdPlayTimer);
            this._adPlayTimer.stop();
         }
         if(param1)
         {
            this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_FRONT_LOAD_COMPLETE));
         }
         this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_VIDEO_PLAY_COMPLETE));
         this._eventDispather.dispatchEvent(new ADEvent(ADEvent.FRONT_DONE));
         if(this._totalTime)
         {
            this.seedSo(this._totalTime);
         }
      }
      
      private function seedSo(param1:Number) : void {
         var t:Number = param1;
         this._soinfo.seedTime = new Date().getTime();
         this._soinfo.nowTime = t;
         try
         {
            AdFsoTools.saveADRefreshInfo(this._soinfo);
         }
         catch(e:Error)
         {
            trace(e.getStackTrace());
         }
      }
      
      private function sendData(param1:Array) : void {
         var _loc2_:* = 0;
         var _loc3_:Object = null;
         var _loc4_:String = null;
         if((param1) && param1.length > 0)
         {
            _loc2_ = 0;
            while(_loc2_ < param1.length)
            {
               _loc3_ = param1[_loc2_] as Object;
               if((_loc3_) && (_loc3_.hasOwnProperty("U")))
               {
                  _loc4_ = param1[_loc2_].U as String;
                  if((_loc4_) && !(_loc4_.indexOf("http://") == -1))
                  {
                     sendToURL(new URLRequest(_loc4_));
                  }
               }
               _loc2_++;
            }
         }
      }
      
      private function sendReadyOrError() : void {
         this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_FRONT_READY_OR_ERROR,{"adtime":this._totalTime}));
      }
      
      private function dataObjeded(param1:GroupData) : Object {
         var _loc3_:Array = null;
         var _loc4_:Array = null;
         var _loc5_:Array = null;
         var _loc6_:* = 0;
         var _loc7_:ADData = null;
         var _loc8_:* = 0;
         var _loc9_:ADData = null;
         var _loc10_:* = 0;
         var _loc11_:ADData = null;
         var _loc2_:Object = new Object();
         _loc2_.P = param1.P;
         if((param1.JS) && param1.JS.length > 0)
         {
            _loc3_ = [];
            _loc6_ = 0;
            while(_loc6_ < param1.JS.length)
            {
               _loc7_ = param1.JS[_loc6_] as ADData;
               _loc3_.push(this.creatADObject(_loc7_));
               _loc6_++;
            }
         }
         _loc2_.JS = _loc3_;
         if((param1.VAL) && param1.VAL.length > 0)
         {
            _loc4_ = [];
            _loc8_ = 0;
            while(_loc8_ < param1.VAL.length)
            {
               _loc9_ = param1.VAL[_loc8_] as ADData;
               _loc4_.push(this.creatADObject(_loc9_));
               _loc8_++;
            }
         }
         _loc2_.VAL = _loc4_;
         if((param1.SEED) && param1.SEED.length > 0)
         {
            _loc5_ = [];
            _loc10_ = 0;
            while(_loc10_ < param1.SEED.length)
            {
               _loc11_ = param1.SEED[_loc10_] as ADData;
               _loc4_.push(this.creatADObject(_loc11_));
               _loc10_++;
            }
         }
         _loc2_.SEED = _loc5_;
         return _loc2_;
      }
      
      private function creatADObject(param1:ADData) : Object {
         var _loc2_:Object = {};
         _loc2_.AT = param1.AT;
         _loc2_.RST = param1.RST;
         _loc2_.RS = param1.RS;
         _loc2_.AL = param1.AL;
         _loc2_.SU = param1.SU;
         _loc2_.SUS = param1.SUS;
         _loc2_.SUE = param1.SUE;
         _loc2_.CUM = param1.CUM;
         _loc2_.CU = param1.CU;
         _loc2_.VT = param1.VT;
         _loc2_.VC = param1.VC;
         _loc2_.W = param1.W;
         _loc2_.H = param1.H;
         _loc2_.CF = param1.CF;
         _loc2_.JS = param1.JS;
         _loc2_.BRS = param1.BRS;
         return _loc2_;
      }
      
      private function checkFC() : void {
         var _loc1_:Object = AdFsoTools.getADHoldingInfo();
         if(!_loc1_)
         {
            _loc1_ = new Object();
         }
         if(_loc1_.fc == undefined || _loc1_.fc == 0)
         {
            _loc1_.fc = 1;
            _loc1_.time = new Date().getTime();
         }
         else
         {
            _loc1_.fc = _loc1_.fc + 1;
         }
         var _loc2_:* = false;
         var _loc3_:* = false;
         var _loc4_:Boolean = this.judgeFSOAvaiable();
         if(!_loc4_)
         {
            this._st = 2;
            this._bt = 5;
            _loc2_ = true;
         }
         trace("whywhy judgeFSOAvaiable: ",_loc4_,_loc2_);
         _loc4_ = this.judgeIsValidTime();
         if(!_loc4_)
         {
            _loc3_ = true;
         }
         var _loc5_:Number = Math.abs(new Date().getTime() - _loc1_.time);
         if(_loc1_.fc > 3 && _loc5_ > 1000 * 60 * 60)
         {
            this._st = 2;
            this._bt = 4;
            _loc2_ = true;
         }
         if(_loc2_)
         {
            this.showADHolder(false);
         }
         else
         {
            if(_loc3_)
            {
               this.sendADTimeReport();
            }
            this.playVideo();
            AdFsoTools.saveADHoldingInfo(_loc1_);
         }
      }
      
      private function sendADTimeReport() : void {
         var _loc1_:Object = {};
         _loc1_.type = "front";
         _loc1_.time = 0;
         _loc1_.fa = this._FSOavailable;
         _loc1_.last = AdFsoTools.getADTimeInfo();
         this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_BLOCK_NOTICE_REPORT,_loc1_));
      }
      
      private function judgeIsValidTime() : Boolean {
         var _loc1_:* = true;
         var _loc2_:Number = AdFsoTools.getADTimeInfo();
         var _loc3_:Number = new Date().getTime();
         if(Math.abs(_loc3_ - _loc2_) > this.AD_CHECK_TIMEOUT)
         {
            _loc1_ = false;
         }
         return _loc1_;
      }
      
      private function judgeFSOAvaiable() : Boolean {
         var settings:* = undefined;
         try
         {
            settings = SharedObject.getLocal("YOUKU_FSO_PROXY","/");
            settings.data["test"] = true;
            settings.flush();
         }
         catch(e:Error)
         {
            _FSOavailable = false;
            return false;
         }
         this._FSOavailable = true;
         return true;
      }
      
      public function showADHolder(param1:Boolean) : void {
         var _loc3_:String = null;
         var _loc4_:String = null;
         var _loc5_:String = null;
         var _loc6_:String = null;
         if(param1)
         {
            _loc3_ = "FATAL_ERROR";
            _loc4_ = "CHANGE_BROWSER_ERROR";
            _loc5_ = "ad_blocked";
            _loc6_ = "7000";
            this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_HOLDER_SHOW,
               {
                  "level":_loc3_,
                  "message":_loc5_,
                  "type":_loc4_,
                  "code":_loc6_
               }));
            this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_BLOCK_REPORT,
               {
                  "st":this._st,
                  "bt":this._bt
               }));
            return;
         }
         var _loc2_:Number = YoukuAdManager.adHoldMediator.getDisplayTime();
         if(_loc2_ == 0)
         {
            this._adholderCallback = null;
            this.onADHolderFinished();
            return;
         }
         this._adholderCallback = null;
         this.showADHolderHelper(ADConstant.FRONT_AD);
         this._eventDispather.dispatchEvent(new YoukuAdEvent(YoukuAdEvent.AD_HOLDER_SHOW_IN_FRONT));
      }
      
      private function showADHolderHelper(param1:String, param2:Number = 0) : void {
         YoukuAdManager.adHoldMediator.show(param1,this._st,this._bt,param2);
         this._isShowHolder = true;
         this.onAdPlayTimer(null);
      }
      
      private function onADHolderFinished() : void {
         if(this._adholderCallback == null)
         {
            this.playVideo();
            return;
         }
         this._adholderCallback.call();
      }
      
      private function resetFC() : void {
         AdFsoTools.saveADHoldingInfo(
            {
               "fc":0,
               "time":new Date().getTime()
            });
      }
      
      private function recordTime() : void {
         var _loc1_:Number = new Date().getTime();
         AdFsoTools.saveADTimeInfo(_loc1_);
      }
      
      private function playVideo() : void {
         this.sendReadyOrError();
         this.allDone(true);
      }
      
      private function seedHandler() : void {
         this._eventDispather.addEventListener(ADEvent.VIDEO_PLAYING,this.onPlayerPlaying);
         this._eventDispather.addEventListener(ADEvent.VIDEO_END,this.onPlayerOver);
      }
      
      private function onPlayerPlaying(param1:ADEvent) : void {
         var _loc2_:ADData = null;
         if((this._groupData.SEED) && this._groupData.SEED.length > 0)
         {
            _loc2_ = this._groupData.SEED[0] as ADData;
            if(_loc2_)
            {
               this.sendData(_loc2_.SUS);
               if((_loc2_.VT) && _loc2_.VT == 1)
               {
                  AdOpenWindow.open(new URLRequest(String(_loc2_.VC)),"_self");
               }
               this._eventDispather.removeEventListener(ADEvent.VIDEO_PLAYING,this.onPlayerPlaying);
            }
         }
      }
      
      private function onPlayerOver(param1:ADEvent) : void {
         var _loc2_:ADData = null;
         if((this._groupData.SEED) && this._groupData.SEED.length > 0)
         {
            _loc2_ = this._groupData.SEED[0] as ADData;
            if(_loc2_)
            {
               this.sendData(_loc2_.SUE);
               this._eventDispather.removeEventListener(ADEvent.VIDEO_END,this.onPlayerOver);
            }
         }
      }
   }
}
